package com.jinzhi.jzweb.controller;


import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.type.EnumErrorCode;
import com.jinzhi.common.utils.EhCacheUtil;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.controller.moduleConfig.StuSignUpComRealityController;
import com.jinzhi.jzweb.domain.ExaminationBatchComDO;
import com.jinzhi.jzweb.domain.ExaminationResultsComDO;
import com.jinzhi.jzweb.domain.StuSignUpComDO;
import com.jinzhi.jzweb.domain.StuSignUpRequest;
import com.jinzhi.jzweb.domain.moduleConfig.CareStuSignUpComRealityDO;
import com.jinzhi.jzweb.pojo.ErroeDownVo;
import com.jinzhi.jzweb.pojo.ErrorCodeVo;
import com.jinzhi.jzweb.pojo.StuSignUpComVo;
import com.jinzhi.jzweb.pojo.StuSignUpComVo2;
import com.jinzhi.jzweb.pojo.moduleConfig.CareStuSignUpComRealityDownloadVo;
import com.jinzhi.jzweb.service.*;
import com.jinzhi.jzweb.service.moduleConfig.CareStuSignUpComRealityService;
import com.jinzhi.jzweb.strategy.factory.PayStrategyFactory;
import com.jinzhi.jzweb.utils.EasyPoiUtil;
import com.jinzhi.sys.domain.UserDO;
import com.jinzhi.sys.service.SysUserRelevancyService;
import com.jinzhi.sys.service.UserService;
import io.swagger.annotations.*;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.*;

/**
 * 
 * <pre>
 * 考生报名   第一次加密
 * </pre>
 * <small> 2023-05-05 08:52:02 | lance</small>downloadImportStu
 */
@Controller
@RequestMapping("/jzweb/stuSignUpCom")
@Api(value = "用户需求后台管理", tags = "用户需求后台管理")
public class StuSignUpComController extends BaseController {


	private final PayStrategyFactory payStrategyFactory;

	private final StuSignUpComService stuSignUpComService;

	private final StuSignUpComService stuSignUpService;

	private final UserService userService;

	private final ExaminationBatchComService examinationBatchService;

	private final ExaminationAnswerSheetComService examinationAnswerSheetService;

	private final SysUserRelevancyService userRelevancyService;

	@Autowired
	private CareStuSignUpComRealityService careStuSignUpComRealityService;
	private final ExaminationResultsComService examinationResultsComService;

	public StuSignUpComController(PayStrategyFactory payStrategyFactory, StuSignUpComService stuSignUpComService, StuSignUpComService stuSignUpService, UserService userService, ExaminationBatchComService examinationBatchService, ExaminationAnswerSheetComService examinationAnswerSheetService, SysUserRelevancyService userRelevancyService, ExaminationResultsComService examinationResultsComService) {
		this.payStrategyFactory = payStrategyFactory;
		this.stuSignUpComService = stuSignUpComService;
		this.stuSignUpService = stuSignUpService;
		this.userService = userService;
		this.examinationBatchService = examinationBatchService;
		this.examinationAnswerSheetService = examinationAnswerSheetService;
		this.userRelevancyService = userRelevancyService;
		this.examinationResultsComService = examinationResultsComService;
	}

	@Log("考生重考报名")
	@PostMapping("/reExam")
	@ResponseBody
	@RequiresPermissions("jzwb:stuSignUp:reExam")
	public Result<String> reExam(Long id) {
		StuSignUpComDO s = stuSignUpService.selectById(id);
		s.setState(8);//将考试转态“已考完”更改为“考试中”
		stuSignUpService.updateById(s);
		Map map = new HashMap<String,String>();
		map.put("stu_sign_id", id);
		examinationResultsComService.delete(new EntityWrapper<ExaminationResultsComDO>().eq("stu_sign_id",id));
	boolean b=	examinationAnswerSheetService.deleteByMap(map);


		return Result.ok("操作成功！");


	}


	@GetMapping()
	@RequiresPermissions("jzweb:stuSignUpCom:stuSignUpCom")
	String StuSignUpCom(Integer types,Model model){
		model.addAttribute("types",types);
	    return "jzweb/stuSignUpCom/stuSignUpCom";
	}



	@GetMapping("/stuSignUpComNum2")
	@RequiresPermissions("jzweb:stuSignUpCom:stuSignUpComNum2")
	String stuSignUpComNum2(Integer types,Model model){
		model.addAttribute("types",types);
		return "jzweb/stuSignUpCom/stuSignUpComNum2";
	}




	/**
	 * 赛场录入
	 * @param id
	 * @param model
	 * @return
	 */
	@GetMapping("/stuSignUpComEnter/{id}")
	@RequiresPermissions("jzweb:stuSignUpCom:resetPwd1s")
	String stuSignUpComEnter(@PathVariable("id") Long id,Model model){
	StuSignUpComDO stuSignUpComDO=	stuSignUpService.selectById(id);
		model.addAttribute("stuSignUpCom",stuSignUpComDO);
		return "jzweb/stuSignUpCom/enter";
	}

	/**
	 * 导如模板 信息
	 * @throws Exception
	 */
	@GetMapping("/exportList")
	@ResponseBody
	public void exportlist( HttpServletRequest request, HttpServletResponse responseexa) throws Exception{

		List<StuSignUpComVo2> list = new LinkedList<>();
		//导出操作
		EasyPoiUtil.exportExcel(list, "选手导入模板", "选手导入模板", StuSignUpComVo2.class, "选手导入模板", responseexa);

	}

		/**
         * 第一次加密选手导出信息
         *
         * @param response
         */
	@GetMapping("/downloadImportStu")
	@RequiresPermissions("jzweb:stuSignUpCom:import")
	@ResponseBody
	public void downloadImportTemplate(HttpServletResponse response,StuSignUpComDO stuSignUpComDTO) {
		List<CareStuSignUpComRealityDownloadVo> list1 = new LinkedList<>();
		Wrapper<StuSignUpComDO> wrapper = new EntityWrapper<StuSignUpComDO>().orderBy("com_nums", true);

		if(StringUtils.isNotBlank(stuSignUpComDTO.getName())){
			wrapper.like("name",stuSignUpComDTO.getName());
		}
		if(stuSignUpComDTO.getCbatchName()!=null){
			ExaminationBatchComDO examinationBatchComDO1=	examinationBatchService.findOneByKv("name",stuSignUpComDTO.getCbatchName());

			wrapper.like("cbatch_id",examinationBatchComDO1.getId().toString());
		}
		wrapper.orderBy("num2",true);
		List<StuSignUpComDO> list=stuSignUpComService.selectList(wrapper);
		for(StuSignUpComDO li:list){
			CareStuSignUpComRealityDownloadVo stuSignUpComVo=new CareStuSignUpComRealityDownloadVo();
			BeanUtils.copyProperties(li,stuSignUpComVo);
			if(null!=li.getCbatchId()){
				ExaminationBatchComDO examinationBatchComDO = examinationBatchService.selectById(li.getCbatchId());
				stuSignUpComVo.setCbatchName(examinationBatchComDO.getName());
			}
			stuSignUpComVo.setName(li.getName());
			stuSignUpComVo.setIdNumber(li.getIdNumber());
			stuSignUpComVo.setTicketNumber(li.getTicketNumber());
			stuSignUpComVo.setUnitName(li.getUnitName());
			stuSignUpComVo.setProvince(li.getProvince() + ","+li.getCity());
			Wrapper<CareStuSignUpComRealityDO> eq=new EntityWrapper<>();
			eq.eq("num2", li.getNum2());
			CareStuSignUpComRealityDO careStuSignUpComRealityDO = careStuSignUpComRealityService.selectOne(eq);
			if (null!=careStuSignUpComRealityDO.getLlCqNumber() && !careStuSignUpComRealityDO.getLlCqNumber().equals("")){
				stuSignUpComVo.setRecordNumber(careStuSignUpComRealityDO.getLlCqNumber());
			}
			list1.add(stuSignUpComVo);
		}
		//导出操作
		EasyPoiUtil.exportExcel(list1, "考生报名信息导出", "考生报名信息导出", CareStuSignUpComRealityDownloadVo.class, "考生报名信息导出", response);
	}


	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:stuSignUpCom:stuSignUpCom")
	public Result<Page<StuSignUpComDO>> list(StuSignUpComDO stuSignUpComDTO){

		Wrapper<StuSignUpComDO> wrapper=new EntityWrapper<>();

		if(StringUtils.isNotBlank(stuSignUpComDTO.getName())){
			wrapper.like("name",stuSignUpComDTO.getName());
		}
		if(null!=stuSignUpComDTO.getType()){
			wrapper.eq("competition_type",stuSignUpComDTO.getType());
		}
		if(StringUtils.isNotBlank(stuSignUpComDTO.getCbatchName())){
			ExaminationBatchComDO examinationBatchComDO1=	examinationBatchService.findOneByKv("name",stuSignUpComDTO.getCbatchName());
			if(examinationBatchComDO1!=null){
				wrapper.like("cbatch_id",examinationBatchComDO1.getId().toString());
			}

		}

		// 查询列表数据
		Page<StuSignUpComDO> page = stuSignUpComService.selectPage(getPage(StuSignUpComDO.class),wrapper);

		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				StuSignUpComDO obj = (StuSignUpComDO) page.getRecords().get(i);
			ExaminationBatchComDO examinationBatchComDO=examinationBatchService.selectById(obj.getCbatchId());
			if (obj.getNum2()!=null&&!obj.getNum2().equals("")){
					Wrapper<CareStuSignUpComRealityDO> eq = new EntityWrapper<>();
					eq.eq("num2", obj.getNum2());
					CareStuSignUpComRealityDO careStuSignUpComRealityDO = careStuSignUpComRealityService.selectOne(eq);
					if (careStuSignUpComRealityDO!=null) {
						if (careStuSignUpComRealityDO.getLlCqNumber() != null && !careStuSignUpComRealityDO.getLlCqNumber().equals("")) {
							obj.setLlCqNumber(careStuSignUpComRealityDO.getLlCqNumber());
						}
					}
			}
			if(examinationBatchComDO!=null){
				obj.setCbatchName(examinationBatchComDO.getName());
			}

			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:stuSignUpCom:add")
	String add(){

	    return "jzweb/stuSignUpCom/add";
	}


	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:stuSignUpCom:edit")
	String edit(@PathVariable("id") Long id,Model model){
		StuSignUpComDO stuSignUpCom = stuSignUpComService.selectById(id);
		model.addAttribute("stuSignUpCom", stuSignUpCom);
		return "jzweb/stuSignUpCom/edit";
	}


	@Log("添加考生报名")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:stuSignUpCom:add")
	public Result<String> save( StuSignUpComDO stuSignUpCom){
		Integer maxNum=stuSignUpComService.MaxNum(stuSignUpCom.getCbatchId());
		ExaminationBatchComDO examinationBatchComDO=examinationBatchService.selectById(stuSignUpCom.getCbatchId());
		if(examinationBatchComDO==null){
			return Result.fail("出现了错误，考试批次不存在！");
		}
		if(StringUtils.isBlank(examinationBatchComDO.getCompetitionName())){
			return Result.fail("未录入竞赛编号无法进行录入！");
		}
		stuSignUpCom.setState(3);
		if(stuSignUpCom.getTypes()==3){
			stuSignUpCom.setCourt("A");
		}
		if(maxNum==null){
			maxNum=0;
		}
		Integer nums=maxNum+1;
		String comName=examinationBatchComDO.getCompetitionName()+"00"+nums;
		stuSignUpCom.setComNum(nums);
		stuSignUpCom.setComNums(comName);

		stuSignUpCom.setSignUpTime(new Date());
		stuSignUpComService.insert(stuSignUpCom);
		return Result.ok();
	}

	/**
	 * 理论赛道录入
	 * @param stuSignUpCom
	 * @return
	 */
	@Log("赛场录入")
	@ResponseBody
	@RequestMapping("/updateEnter")
	@RequiresPermissions("jzweb:stuSignUpCom:resetPwd1s")
	public Result<String>  updateEnter( StuSignUpComDO stuSignUpCom){
		StuSignUpComDO stuSignUpComDO1=	stuSignUpComService.selectById(stuSignUpCom.getId());
//
//		List<StuSignUpComDO> list =	stuSignUpComService.findByKv("num1",stuSignUpCom.getNum1(),
//				"court",stuSignUpCom.getCourt(),"cbatch_id",stuSignUpComDO1.getCbatchId());
		if(stuSignUpCom.getCourt()==null){
			return  Result.fail("请录入赛道！");
		}
		if(stuSignUpCom.getNum1()==null){
			return  Result.fail("请录入第一次加密！");
		}
		Wrapper<StuSignUpComDO> wrapper=new EntityWrapper<>();
		wrapper.eq("cbatch_id",stuSignUpComDO1.getCbatchId());
		wrapper.eq("num1",stuSignUpCom.getNum1().replaceAll(" ",""));
		List<StuSignUpComDO> list =	stuSignUpComService.selectList(wrapper);
		if(list.size()>0){
			for(StuSignUpComDO li:list){
				if(!li.getId().equals(stuSignUpCom.getId())){
					return  Result.fail("加密序号重复！");
				}
			}

		}
		boolean update = stuSignUpComService.updateById(stuSignUpCom);
		return update ? Result.ok() : Result.fail();
	}


	@Log("修改考生报名")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:stuSignUpCom:edit")
	public Result<String>  update( StuSignUpComDO stuSignUpCom){

		StuSignUpComDO stuSignUpComDO1=	stuSignUpComService.selectById(stuSignUpCom.getId());

//		List<StuSignUpComDO> list =	stuSignUpComService.findByKv("num2",stuSignUpCom.getNum1(),
//				"court",stuSignUpCom.getCourt(),"cbatch_id",stuSignUpComDO1.getCbatchId());

		Wrapper<StuSignUpComDO> wrapper=new EntityWrapper<>();
		wrapper.eq("court",stuSignUpComDO1.getCourt());
		wrapper.eq("cbatch_id",stuSignUpComDO1.getCbatchId());
		wrapper.eq("num2",stuSignUpCom.getNum2());
		List<StuSignUpComDO> list =	stuSignUpComService.selectList(wrapper);
		if(list.size()>0){
			for(StuSignUpComDO li:list){
				if(!li.getId().equals(stuSignUpCom.getId())){
					return  Result.fail("加密序号重复！");
				}
			}

		}

		boolean update = stuSignUpComService.updateById(stuSignUpCom);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除考生报名")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:stuSignUpCom:remove")
	public Result<String>  remove( Long id){
		stuSignUpComService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除考生报名")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:stuSignUpCom:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		stuSignUpComService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}


	/**
	 * 导出错误信息
	 *
	 * @param request
	 * @param response
	 * @throws Exception
	 * @author kl
	 */
	@Log("导出错误信息")
	@GetMapping("/importComError")
	@ResponseBody
	@Transactional
	@RequiresPermissions("jzweb:stuSignUp:import")
	public void download(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 告诉浏览器用什么软件可以打开此文件
		response.setHeader("content-Type", "application/vnd.ms-excel");
		// 下载文件的默认名称
		response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("考生报名导入错误信息", "UTF-8") + ".xls");
		//编码
		response.setCharacterEncoding("UTF-8");
		String jsonArray = EhCacheUtil.get("stuSignComUp" + this.getUserId()).toString();
		JSONArray arrayList = JSONArray.parseArray(jsonArray);
		//转换为目标对象list
		List<ErroeDownVo> groupList = JSONObject.parseArray(arrayList.toJSONString(), ErroeDownVo.class);
		Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ErroeDownVo.class, groupList);
		workbook.write(response.getOutputStream());
	}

	/**
	 * 考生信息导入
	 *
	 * @param file excel文件
	 */
	@Log("考生信息导入")
	@PostMapping("/import")
	@ResponseBody
	@Transactional
	@RequiresPermissions("jzweb:stuSignUpCom:import")
	public Result<?> importExcel(HttpServletRequest req, @RequestParam("file") MultipartFile file, String cbatchId,Integer type) {
		//---------------------------------检测导入信息及条件-----------------------------------------
		//第一步--判断文件格式
		if (!"application/vnd.ms-excel".equals(file.getContentType())) {
			return Result.fail("文件格式错误，请选择.xls文件");
		}

		//第二步--解析文件获得数据
		List<StuSignUpComVo> list = EasyPoiUtil.importExcel(file, 1, 1, StuSignUpComVo.class);
		if (list.size() == 0) {
			return Result.fail("Excel数据为空，请完善");
		}


		//第四步--判断该认证批次是否已经建立了理论考试批次；
		//todo 目前定义为只要是认证批次，就一定存在理论考试
		List<ExaminationBatchComDO> examinationBatchDO = examinationBatchService.findByKv("id", Long.parseLong(cbatchId), "type", 0);

		//---------------------------------验证数据并导入-----------------------------------------
		//数据该市行为第三行，第一行标题，第二行表头
		int startRow = 3;
		int cout = 1;//错误信息计数
		List<StuSignUpComDO> upDOList = new ArrayList<>();
		List<ErrorCodeVo> list1 = new ArrayList<>();
		for (int i = 0; i < list.size(); i++) {
			UserDO rrUserDo = null;
			UserDO rsUserDo = null;
			StringBuilder sb = new StringBuilder();
			//第一步验证是否存在空值
			if (StringUtils.isBlank(list.get(i).getName())) {
				sb.append("第" + (i + startRow) + "行姓名未填写，请完善！" + ";");
			} else {
//				if (StringUtils.isBlank(list.get(i).getSex())) {
//					sb.append("第" + (i + startRow) + "行性别未填写，请完善！" + ";");
//				} else {
				if (StringUtils.isBlank(list.get(i).getTicketNumber())) {
					sb.append("第" + (i + startRow) + "行准考证号未填写，请完善！" + ";");
				} else {
					if(1==2) {
						sb.append("第" + (i + startRow) + "行考场名称未填写，请完善！" + ";");
					}else {
						if (StringUtils.isBlank(list.get(i).getIdNumber())) {
							sb.append("第" + (i + startRow) + "行考生编号未填写，请完善！" + ";");
						} else {
										}

							if (sb.length() == 0) {
								//第四步排重验证（自身比较）
								for (int j = 0; j < list.size(); j++) {
									if (i != j) {
										if (list.get(i).getTicketNumber().equals(list.get(j).getTicketNumber())) {
											sb.append("第" + (i + startRow) + "行跟第" + (j + startRow) + "行准考证号重复，重复值：" + list.get(i).getIdNumber() + ";");
										}
									}
								}

								//第六步排重验证（和数据库比较），根据考生名称、考生身份证号码、该场考试的认证批次判断该考生是否已报名该考试
								StuSignUpComDO stuSignUpDO = stuSignUpService.findOneByKv("name", list.get(i).getName(), "id_number", list.get(i).getIdNumber(), "cbatch_id", Long.parseLong(cbatchId));
								if (stuSignUpDO != null) {
									sb.append("第" + (i + startRow) + "行考生已报名该次考试！" + ";");
								}

							}

						}
					}
				}

			if (sb.length() > 0) {
				ErrorCodeVo errorCodeVo = new ErrorCodeVo();
				errorCodeVo.setSeq(cout);
				cout += 1;
				errorCodeVo.setErrorCode(sb.toString());
				list1.add(errorCodeVo);
			} else {
				if (rrUserDo != null) {
					boolean cc = userService.insertNoPW(rrUserDo);
					if (!cc) {
					}
				}
			}

				StuSignUpComDO stuSignUpDO1 = new StuSignUpComDO();
				stuSignUpDO1.setName(list.get(i).getName());//姓名
				stuSignUpDO1.setIdNumber(list.get(i).getIdNumber());//身份证号码
				stuSignUpDO1.setCbatchId(Long.parseLong(cbatchId));//认证批次id
				stuSignUpDO1.setSignUpTime(new Date());//报名时间
				stuSignUpDO1.setDecrypt(0);

				stuSignUpDO1.setType(0);
				stuSignUpDO1.setState(3);//默认已分配

			stuSignUpDO1.setTypes(type);
			if(type==3){
				stuSignUpDO1.setCourt("A");
			}else {
				stuSignUpDO1.setCourt(list.get(i).getCourt());
			}
			stuSignUpDO1.setUnitName(list.get(i).getUnitName());
			stuSignUpDO1.setTeacher(list.get(i).getTeacherName());


				stuSignUpDO1.setTicketNumber(list.get(i).getTicketNumber());//考号

				stuSignUpDO1.setCheckerId(this.getUserId());//默认审核人为导入者
				stuSignUpDO1.setCheckerDate(new Date());//默认审核时间为导入时间
				upDOList.add(stuSignUpDO1);

			}
		Integer maxNum=stuSignUpComService.MaxNum(Long.valueOf(cbatchId));
		if(maxNum==null){
			maxNum=0;
		}
		ExaminationBatchComDO examinationBatchComDO=examinationBatchService.selectById(Long.valueOf(cbatchId));
		if(examinationBatchComDO==null){
			return Result.fail("出现了错误，考试批次不存在！");
		}
		if(StringUtils.isBlank(examinationBatchComDO.getCompetitionName())){
			return Result.fail("未录入竞赛编号无法进行录入！");
		}
		Integer nums=maxNum+1;
		//赋值竞赛编号
		for(StuSignUpComDO li:upDOList){

			String comName=examinationBatchComDO.getCompetitionName()+"00"+nums;
			li.setComNum(nums);
			li.setComNums(comName);
			nums++;
		}

		if (list1.size() == 0) {
			boolean c = stuSignUpService.insertBatch(upDOList, upDOList.size());
			if (c) {
				ExaminationBatchComDO examinationBatchDOs = examinationBatchService.findOneByKv("cbatch_id", Long.parseLong(cbatchId), "type", 1);


				return Result.ok("成功导入" + list.size() + "条数据");
			} else {

				return Result.fail("报名信息导入错误，请稍后重试或联系管理员");
			}
		} else {


			JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(list1));
			//将list1存到缓存中
			EhCacheUtil.put("stuSignComUp" + this.getUserId(), jsonArray);
			return Result.build(EnumErrorCode.FileImportError.getCode(), EnumErrorCode.FileImportError.getMsg());
		}
		}



//	@Log("输入打分页面查询")
//	@PostMapping( "/getStuSignByCourt2")
//	@ApiOperation(value = "输入打分页面查询", notes = "输入打分页面查询")
//	@ApiImplicitParams({
//			@ApiImplicitParam(name = "court2", value = "court2", required = true, dataType = "String"),
//			@ApiImplicitParam(name = "distinguish", value = "distinguish", required = true, dataType = "String"),
//			@ApiImplicitParam(name = "curr", value = "curr", required = true, dataType = "Integer"),
//			@ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "Integer"),
//	})
//	@ApiResponses({@ApiResponse(code = 0, message = "操作成功"),
//			@ApiResponse(code = 500, message = "服务器内部异常")})
//	@ResponseBody
//	public Result<Object> getStuSignByCourt2(@RequestParam(value = "court2") String court2,
//											 @RequestParam(value = "distinguish") String distinguish,
//											 @RequestParam(value = "curr") Integer curr,
//											 @RequestParam(value = "pageSize") Integer pageSize) throws Exception {
//		return Result.ok(payStrategyFactory.get(distinguish).getStuSignByCourt2(court2,curr,pageSize));
//	}

//	@Log("打分列表页面")
//	@GetMapping("/pageReturn")
//	public String pageReturn(String distinguish,Model model) throws Exception {
//		String cbatchId = userRelevancyService.selectById(this.getUser().getUserRelevancyId()).getTrack();
//		model.addAttribute("pid",cbatchId);
//		return payStrategyFactory.get(distinguish).pageReturn();
//	}


	@Log("加密弹窗")
	@GetMapping("/encryptionJudge")
	public String encryptionJudge(){
		return "jzweb/encryptionJudge/encryptionJudge";
	}

	@Log("查询批次")
	@PostMapping( "/getbatch")
	@ApiOperation(value = "查询批次", notes = "查询批次")
	@ResponseBody
	public Result<Object> getbatch(){
		return Result.ok(examinationBatchService.selectList(new EntityWrapper<ExaminationBatchComDO>().
				eq("type",3).
				notIn("state",0,2,9)));
	}


//	@Log("题目打分")
//	@GetMapping("/markReturn")
//	public String markReturn(String distinguish, Integer type) throws Exception {
//		return payStrategyFactory.get(distinguish).markReturn(type);
//	}

	@Log("打分导出")
	@GetMapping("/downloadMark")
	@ResponseBody
	public void downloadMark(HttpServletResponse response,String distinguish,String id)  throws Exception {
		payStrategyFactory.get(distinguish).downloadImportTemplate(response,id);
	}


	@Log("解密查询")
	@GetMapping("/getStuGignUpCom")
	@ResponseBody
	public Result<Object> getStuGignUpCom(Integer curr,Integer pageSize){
		return  Result.ok(stuSignUpService.getStuGignUpCom(curr,pageSize));
	}


	@Log("解密导出")
	@GetMapping("/stuGignUpCom")
	@ResponseBody
	public void stuGignUpCom(HttpServletResponse response)  throws Exception {
		stuSignUpService.stuGignUpCom(response);
	}

	@Log("一键解密")
	@PostMapping("/decrypt")
	@ApiOperation(value = "一键解密", notes = "一键解密")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "StuSignUpRequest", value = "StuSignUpRequest", required = true, dataType = "StuSignUpRequest")
	})
	@ResponseBody
	public Result<Object> decrypt(@RequestBody StuSignUpRequest stuSignUpRequest){
		return  Result.ok(stuSignUpService.updateBatchById(stuSignUpRequest.getStuSignUpComDOS()));
	}

	@Log("一键生成二次加密号和密码")
	@ResponseBody
	@GetMapping("/touchSign")
	public Result<?> touchSign(){
		stuSignUpService.touchSign();
		return  Result.ok();
	}




}
